package bufferings.lab.basic.test;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import java.util.Collections;

import org.junit.Test;
import org.slim3.tester.AppEngineTestCase;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Transaction;

public class HowIsEmptyListStored extends AppEngineTestCase {

  public static final String KIND = HowIsEmptyListStored.class.getSimpleName();

  public static final String KEY_NAME = "keyName";

  public static final String PROP_NAME = "prop1";

  @Test
  public void 空のリストはNull値プロパティになる() throws Exception {
    Entity entity = new Entity(KIND, KEY_NAME);
    entity.setProperty(PROP_NAME, Collections.EMPTY_LIST);

    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    Key key = ds.put((Transaction) null, entity);

    Entity storedEntity = ds.get((Transaction) null, key);
    assertThat(storedEntity.hasProperty(PROP_NAME), is(true));
    assertThat(storedEntity.getProperty(PROP_NAME), is(nullValue()));
  }

}
